package window;

import javax.swing.*;

public class JOptionPaneMultiInput {

    JTextField[] fields;
    JPanel panel;
    String note;

    public JOptionPaneMultiInput(String[] args, String note) {
        this.note = note;
        panel = new JPanel();
        fields = new JTextField[args.length];
        for(int i = 0; i < args.length; i ++) {
            fields[i] = new JTextField(5);
            panel.add(new JLabel(args[i] + ":"));
            panel.add(fields[i]);
            panel.add(Box.createHorizontalStrut(15));
        }
    }

    public int[] show(){
        int[] retDat = new int[fields.length];
        int result = JOptionPane.showConfirmDialog(null, panel,
                 note, JOptionPane.OK_CANCEL_OPTION);
        if (result == JOptionPane.OK_OPTION) {
            for (int i = 0; i < fields.length; i++)
                if(!fields[i].getText().equals(""))
                    retDat[i] = Integer.parseInt(fields[i].getText());
                else
                    retDat[i] = -2;
            return retDat;
        }
        return null;
    }
}
